package com.kdtech.entity.data.save;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.ansj.app.keyword.Keyword;

import com.kdtech.utils.SerializeUtils;

/***
 * 信息的存储
 *
 * @author kd-12
 *
 */
public class SaveMeta implements Serializable {
	/**
	 * 信息的Url
	 */
	private String url;
	/**
	 * 信息的Url md5
	 */
	private byte[] _id;
	/**
	 * 1: 新闻 2：视频 3:论坛 4：问答/知道 5：平媒 6：博客
	 */
	private Integer type;
	/**
	 * 标题 (Length<=100)
	 */
	private String title;
	/**
	 * 正文
	 */
	private String content;
	/**
	 * 摘要
	 */
	private String TextSummary;
	/**
	 * 信息的日期
	 */
	private Long date;
	/**
	 * 来源
	 */
	private Integer source;
	/**
	 * 网站入口ID
	 */
	private Integer entryId;
	/**
	 * 地域属性
	 */
	private Integer AddressValue;
	/**
	 * 点击数
	 */
	private Integer clickNum;
	/**
	 * 评论数/跟帖数
	 */
	private Integer commentNum;

	/**
	 * 作者
	 */
	private String author;
	/**
	 * 作者Id
	 */
	private Integer authorId;
	/**
	 * 附加文件的偏移量
	 */
	private Long addPos;

	/**
	 * 1个bye 机器IP后缀 剩余为主题Id
	 */
	private Long TopId;

	/**
	 * 是否重点关注信息 0 普通 1 {1}类重点 2 {2}类重点
	 */
	private Integer InforLeve = 0;

	/**
	 * 更新信息属性地址
	 */
	private String updateUrl = null;
	/**
	 * 最后更新时间
	 */
	private Long LastUpdateTime = 0l;


	/**
	 * 根据文章标题和内容得到的主题关键字列表
	 */
	private byte[] keywordMeta=null;
     /**
      * 存储的网页快照原始html
      */
	private byte[] htmlBytes=null;
	/**
	 * 正负面属性 0负面 1中性 2正面
	 */
	private int PosNeg=1;
	public String getTextSummary() {
		return TextSummary;
	}

	public void setTextSummary(String textSummary) {
		TextSummary = textSummary;
	}
	public Long getTopId() {
		return TopId;
	}

	public void setTopId(Long topId) {
		TopId = topId;
	}

	public int getPosNeg() {
		return PosNeg;
	}

	public void setPosNeg(int posNeg) {
		PosNeg = posNeg;
	}

	public byte[] getHtmlBytes() {
		return htmlBytes;
	}

	public void setHtmlBytes(byte[] htmlBytes) {
		this.htmlBytes = htmlBytes;
	}
	public List<KeywordMeta> getKeywordMeta() {
		try {
			if(keywordMeta!=null){
				Object object=SerializeUtils.deserialize(keywordMeta);
				return (List<KeywordMeta>) object;
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

	public void setKeywordMetaConvert(List<Keyword> keyword) {
		byte[] serialize = null;
		if(keyword!=null && keyword.size()>0){
			List<KeywordMeta> listKeyword  =  new ArrayList<KeywordMeta>();
			for (Keyword kw : keyword) {
				KeywordMeta tkw = new KeywordMeta();
				tkw.setName(kw.getName());
				tkw.setFreq(kw.getFreq());
				tkw.setScore(kw.getScore());
				listKeyword.add(tkw);
			}
			try {
				serialize = SerializeUtils.serialize((Serializable) listKeyword);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		this.keywordMeta = serialize;
	}

	public void setKeywordMeta(List<KeywordMeta> keyword) {
		byte[] serialize = null;
		if(keyword!=null && keyword.size()>0){
			try {
				serialize = SerializeUtils.serialize((Serializable) keyword);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		this.keywordMeta = serialize;
	}

	public Integer getInforLeve() {
		return InforLeve;
	}

	public void setInforLeve(Integer inforLeve) {
		InforLeve = inforLeve;
	}
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {		
		return content;
	}

	public void setContent(String content) {
		this.content=content;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
	public Integer getSource() {
		return source;
	}

	public void setSource(Integer source) {
		this.source = source;
	}

	public Integer getAddressValue() {
		return AddressValue;
	}

	public void setAddressValue(Integer addressValue) {
		AddressValue = addressValue;
	}
	public byte[] get_id() {
		return _id;
	}

	public void set_id(byte[] _id) {
		this._id = _id;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public Long getDate() {
		return date;
	}

	public void setDate(Long date) {
		this.date = date;
	}

	public Long getAddPos() {
		return addPos;
	}

	public void setAddPos(Long addPos) {
		this.addPos = addPos;
	}
	public Integer getClickNum() {
		return clickNum;
	}

	public void setClickNum(Integer clickNum) {
		this.clickNum = clickNum;
	}

	public Integer getCommentNum() {
		return commentNum;
	}

	public void setCommentNum(Integer commentNum) {
		this.commentNum = commentNum;
	}


	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}


	public Integer getAuthorId() {
		return authorId;
	}

	public void setAuthorId(Integer authorId) {
		this.authorId = authorId;
	}
	public String getUpdateUrl() {
		return updateUrl;
	}

	public void setUpdateUrl(String updateUrl) {
		this.updateUrl = updateUrl;
	}

	public Long getLastUpdateTime() {
		return LastUpdateTime;
	}

	public void setLastUpdateTime(Long lastUpdateTime) {
		LastUpdateTime = lastUpdateTime;
	}

	public void setKeywordMeta(byte[] keywordMeta) {
		this.keywordMeta = keywordMeta;
	}

	@Override
	public String toString() {
		return "SaveMeta [url=" + url + ", _id=" + Arrays.toString(_id)
				+ ", type=" + type + ", updateUrl="
				+ updateUrl + ", LastUpdateTime=" + LastUpdateTime + ", date="
				+ date + ", addPos=" + addPos + ",  clickNum=" + clickNum + ", commentNum=" + commentNum
				+ ", source=" + source
				+ ", InfoLeve=" + this.InforLeve
				+ "]";
	}


	public Integer getEntryId() {
		return entryId;
	}

	public void setEntryId(Integer entryId) {
		this.entryId = entryId;
	}

	public static void main(String[] args) {
		List<Keyword> list = new ArrayList<Keyword>();
		Keyword s = new Keyword("收到",4,10);
		s.setScore(39);
		list.add(s);
		SaveMeta meta = new SaveMeta();
		meta.setKeywordMetaConvert(list);
		List<KeywordMeta> keyword2 = meta.getKeywordMeta();
		for (KeywordMeta keywordMeta : keyword2) {
			System.out.println(keywordMeta.getName());
			System.out.println(keywordMeta.getFreq());
			System.out.println(keywordMeta.getScore());
		}
	}
}
